package com.wqtz.chechai.adapter;

import android.view.View;

import com.wqtz.chechai.R;
import com.wqtz.chechai.base.lvbaseadapter.LvBaseAdapter;
import com.wqtz.chechai.base.lvbaseadapter.ViewHolder;
import com.wqtz.chechai.bean.OrderBean;
import com.yinglan.swiperefresh.SwipeMenu;
import com.yinglan.swiperefresh.SwipeMenuListView;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2017/1/18 18:19
 */

public class QuoteFirstFragmentAdapter extends LvBaseAdapter<OrderBean> implements SwipeMenuListView.OnMenuItemClickListener {
	List<OrderBean> datas = new ArrayList<>();
	/*
	* 四种状态
	* 0：审核通过
	* 1：审核中
	* 2：拒绝
	* 3：取消审核*/
	private final int PASS = 0;
	private final int REVIEW = 1;
	private final int REFUSE = 2;
	private final int CANCLE = 3;
	QuoteItemClickCallBack mBack;

	public void setClickListen(QuoteItemClickCallBack mBack) {
		this.mBack = mBack;
	}


	public QuoteFirstFragmentAdapter(int resId) {
		super(resId);
	}

	@Override
	public void bindDatas(final List<OrderBean> data, final int position, ViewHolder holder) {
		datas.clear();
		datas.addAll(data);
		switch (data.get(position).getType()) {
			case PASS: {
				holder.setCirCleImag(R.id.iv_status, R.mipmap.alreadyquote);
				holder.setText(R.id.tv_should_pay, data.get(position).getShouldPay());
			}
			break;
			case REVIEW: {
				holder.setCirCleImag(R.id.iv_status, R.mipmap.review);
				holder.getView(R.id.iv_cicle2).setVisibility(View.INVISIBLE);
				holder.setText(R.id.tv_should_pay,"");
			}
			break;
			case REFUSE: {
				holder.setCirCleImag(R.id.iv_status, R.mipmap.refuse);
				holder.getView(R.id.iv_cicle2).setVisibility(View.INVISIBLE);
				holder.setText(R.id.tv_should_pay,"");
			}
			break;
			case CANCLE:{
				holder.setCirCleImag(R.id.iv_status, R.drawable.loan_canceled);
				holder.getView(R.id.iv_cicle2).setVisibility(View.INVISIBLE);
				holder.setText(R.id.tv_should_pay,"");
			}break;

		}

		holder.setText(R.id.carName, data.get(position).getCarModel() + "");
		holder.setText(R.id.tv_use_time, data.get(position).getCarBuyTime() + "");
		holder.setText(R.id.tv_run_km, data.get(position).getMileage() + "");
		holder.setText(R.id.tv_car_status, data.get(position).getCarStatus() + "");
		holder.setText(R.id.tv_assume_price, data.get(position).getAssumPrice() + "");
		holder.setText(R.id.tv_time, data.get(position).getLastModefyTime() + "");
		holder.getViewHolder().setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				mBack.oItemClickItem(position);
			}
		});


	}

	@Override
	public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
		menu.setViewType(datas.get(position).getType() < 3 ? 1 : 0);
		mBack.oItemClickSwipeMenu(position,menu.getViewType());
		return false;

	}


	@Override
	public int getViewTypeCount() {
		return 2;
	}

	@Override
	public int getItemViewType(int position) {
		if(datas.size()==0){
			return 0;
		}else {
			switch (datas.get(position).getType()){
				case REFUSE:
				case CANCLE:
					return 0;
				case REVIEW:
				case PASS:
					return 1;
			}
		}
		return 1;
	}

	public interface QuoteItemClickCallBack {
		 void oItemClickItem(int positon);
		 void oItemClickSwipeMenu(int positon, int Type);
	}


}
